package com.thomas.generator.util;

import com.sun.org.apache.xerces.internal.dom.PSVIAttrNSImpl;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author xutao
 * @Package com.thomas.generator.util
 * @Description: ${todo}
 * @date 2019/12/11 9:44
 */
public class PropertiesUtil {

    private static Properties properties = new Properties();
    private static AtomicBoolean atomicBoolean = new AtomicBoolean(true);


    public static void load(String propertiesName){
        if(atomicBoolean.compareAndSet(true,false)){
            InputStream inputStream = PropertiesUtil.class.getResourceAsStream(propertiesName);
            try {
                properties.load(inputStream);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        load();
    }

    public static void load(){
        load("/application.properties");
    }

    public static String get(String key){
        if(properties.isEmpty()){
            load();
        }
        return properties.getProperty(key);
    }

}
